package com.dwy2002.user;


import com.dwy2002.common.Result;
import com.dwy2002.common.annotation.RequiresPermission;
import com.dwy2002.enums.Logical;
import com.dwy2002.pojo.dto.users.RoleDTO;
import com.dwy2002.pojo.po.users.Role;
import com.dwy2002.pojo.vo.users.RoleDetailVO;
import com.dwy2002.user.service.IRoleService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 杜伟毅
 * @version 1.0
 * @since 2025/03/16
 */
@RestController
@RequestMapping("/role")
@RequiredArgsConstructor
public class RoleController {
    private final IRoleService service;

    /**
     * 添加角色
     *
     * @param dto 角色DTO
     * @author 杜伟毅
     * @since 2025/3/16 0016 20:56
     */
    @RequiresPermission(value = {"A8"}, logical = Logical.OR)
    @PostMapping
    public Result<Void> appendRole(@RequestBody RoleDTO dto) {
        return service.appendRole(dto);
    }

    /**
     * 修改角色
     *
     * @param dto 角色DTO
     * @author 杜伟毅
     * @since 2025/3/16 0016 23:09
     */
    @RequiresPermission(value = {"A8"}, logical = Logical.OR)
    @PutMapping
    public Result<Void> updateRole(@RequestBody RoleDTO dto) {
        return service.updateRole(dto);
    }

    /**
     * 返回所有角色
     *
     * @author 杜伟毅
     * @since 2025/3/16 0016 23:31
     */
    @RequiresPermission(value = {"A8"}, logical = Logical.OR)
    @GetMapping
    public Result<List<Role>> getRole() {
        return service.getRole();
    }

    /**
     * 删除角色
     *
     * @param id 角色id
     * @author 杜伟毅
     * @since 2025/3/17 0017 21:32
     */
    @RequiresPermission(value = {"A8"}, logical = Logical.OR)
    @DeleteMapping("/{id}")
    public Result<Void> removeRole(@PathVariable String id) {
        return service.removeRole(id);
    }

    /**
     * 获取角色详情
     *
     * @param id 角色id
     * @author 杜伟毅
     * @since 2025/5/14 0014 23:55
     */
    @RequiresPermission(value = {"A8"}, logical = Logical.OR)
    @GetMapping("/{id}")
    public Result<RoleDetailVO> getRoleDetail(@PathVariable String id) {
        return service.getRoleDetail(id);
    }
}
